import {Modal, message} from "antd";

interface UseModalProps {
    delFetch?: (e?: any) => any;
    title?: string;
    name?: "";
    cancelText?: (e?: any) => any;
}

export default function useModal({title = "", name = "", cancelText, delFetch}: UseModalProps): any {
    const handleDelete = row => {
        const desc = cancelText(row);
        Modal.error({
            title: title || "温馨提示",
            content: desc || "是否删除此条数据",
            okText: "确定",
            onOk: async () => {
                try {
                    const deleteIdx = name ? row[name] : row;
                    delFetch(deleteIdx);
                } catch (error) {
                    message.error("删除失败");
                }
            },
        });
    };

    return {deleteModal: handleDelete};
}
